<?php include '../../authorization_check.php' ?>
<?php include '../../checkPCVPCSecretary.php'; ?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-9">
<title>View Instructor Course Details</title>
<SCRIPT TYPE="text/javascript" src= "../../commonutils/util/util.js"> </SCRIPT>
</head>
<style type="text/css">

</style>
<body>

<?php include 'top.html' ?>
<?php include 'notifier.php' ?>


<?php
  session_start();
  $programCode = $_SESSION['programCode'];
  $semesterID = $_SESSION['semesterID'];
?>
  
<FORM NAME ="form1" METHOD ="POST" ACTION = "ViewInstructorCourse.php">
<p>Select the instructor to see the course sections assign to that instructor:</p>

</p>

<table cellpadding=5>
<tr>
<td>
<table border=1 cellpadding="3">
<tr>

<th style="text-align:center">INSTRUCTOR </th>
</tr>
<?php
require_once '../../commonutils/db/DBConnectionManager.php';
	$sqlquery = " select instructorID, concat(firstName, ' ', lastName) as iname from instructor ";
	$result = DBConnectionManager::query($sqlquery);
	while($row = mysql_fetch_assoc($result)){
		echo "<tr>";
		echo "<td><input type=\"radio\" name=\"instructorID\" value= \"".$row['instructorID']."\"> ";
		echo " ".$row['iname']."</td>";

		echo "</tr>";		
	}	
?>

</table>

</p>
</td>
<td>
<input type="submit" value="View details" style="width:100; height:30" name="btnSubmit" onClick="return radioControl(instructorID)">
</td>
</tr>
</table>

</p>  

<?php
require_once '../../commonutils/db/DBConnectionManager.php';

if (isset($_POST['btnSubmit']))
{
	$instructorID = $_POST['instructorID'];
	
	$sqlquery = " select instructorID, concat(firstName, ' ', lastName) as iname from instructor ".
				" where instructorID = ".$instructorID;
	
	// echo $sqlquery."<br>";
	
	$result = DBConnectionManager::query($sqlquery);
	$row = mysql_fetch_assoc($result);
	$iname = $row['iname'];

	echo "The course sections assigned to <b>".$iname."</b> : ";
	echo "</p>";
		
	$sqlquery = " select course.courseCode, course.courseName, section.sectionNumber, count(enrollment.studentID) as cnt".
				" from course, section left outer join enrollment on section.sectionID = enrollment.sectionID ". 
				" where section.courseCode = course.courseCode ".
				" and section.semesterID = ".$semesterID." and course.programCode = ".$programCode.
				" and section.instructorID = ".$instructorID.
				" group by section.courseCode, course.courseName, section.sectionNumber" ;

	/// echo $sqlquery;  
	$result = DBConnectionManager::query($sqlquery);
	$row = mysql_fetch_assoc($result);
	echo "<table border=1>";
	echo "<tr>";
	echo "<th>COURSE CODE </th>";
	echo "<th>COURSE NAME </th>";
	echo "<th>SECTION </th>";
	echo "<th>NUMBER OF STUDENTS </th>";
	echo "</tr>";
	$result = DBConnectionManager::query($sqlquery);
	while($row = mysql_fetch_assoc($result)){
		echo "<tr>";
		echo "<td>".$row['courseCode']."</td>";
		echo "<td>".$row['courseName']."</td>";
		echo "<td>".$row['sectionNumber']."</td>";
		echo "<td>".$row['cnt']."</td>";
		echo "</tr>";		
	}
	echo "</table>";
}

?>
</p>  
</FORM>

<?php include 'bottom.php' ?>


</body>


</html>